#include <iostream>
#include <vector>
#include "overlap.hpp"
#include "vecs_io.hpp"
#include <omp.h>

using namespace std;
using namespace KNNOverlap;

/*
 * 输入: knn图的路径, n_cluster, n_classifier
 * 输出: 质心的坐标
 *
 * read the graph
 * get the centroid for each classifier
 * for each classifier, generate n_cluster points and do the bfs,
 *      each bfs size should not exceed n_item / n_cluster, when there is some overlap for different bfs, stop
 */

int main(int argc, char **argv) {
    if (argc != 6) {
        std::cout << argv[0] << " base_fname train_para_dir n_cluster n_classifier size_variance" << std::endl;
        exit(-1);
    }
    printf("base_fname %s\ntrain_para_dir %s\nn_cluster %s\nn_classifier %s\nsize_variance %s\n", argv[1], argv[2],
           argv[3], argv[4], argv[5]);

    char *base_fname = argv[1];
    char *path = argv[2];
    int n_cluster = atoi(argv[3]);
    int n_classifier = atoi(argv[4]);
    float size_variance = atof(argv[5]);
    int seed = 100;

    vector<vector<int>> graph = read_graph(path);
    int n_item, vec_dim;
    float *base = load_vecs<float>(base_fname, n_item, vec_dim);

#pragma omp parallel for
    for (int i = 0; i < n_classifier; i++) {

        std::vector<int> partition_l = get_partition_l(graph, n_cluster, size_variance, seed + i);
        printf("get partition successfully classifier %d\n", i);

        test_partition_l(partition_l, n_cluster);

        std::vector<std::vector<float >> centroid_l = get_centroids(base, partition_l, vec_dim, n_cluster);
        printf("get centroid_l successfully classifier %d\n", i);

        char centroid_fname[256];
        sprintf(centroid_fname, "%s/Classifier_%d/dataset_partition/centroids.txt", path, i);
        save_centroid(centroid_fname, centroid_l);
        printf("save path successfully %s\n", centroid_fname);
    }
    return 0;
}